package com.simba.server.commands.impl.fetch;

import java.sql.ResultSet;
import java.util.List;
import com.simba.common.command.ICommand;
import com.simba.common.database.DbOperator;

public class FetchPacketOffByNoSyncCmd implements ICommand
{
	public static final String NAME = "FetchPacketOffByNoSyncCmd";
	private final List<Integer> idList;
	private final String sql = "select * from tt_packet_off_info where syncFlag=0 limit 1000;";

	public FetchPacketOffByNoSyncCmd(List<Integer> idList)
	{
		this.idList = idList;
	}

	@Override
	public String getName()
	{
		return FetchPacketOffByNoSyncCmd.NAME;
	}

	@Override
	public Boolean run(Object params)
	{

		Boolean ret = false;

		if (!(params instanceof DbOperator))
		{
			return ret;
		}

		try
		{
			DbOperator dbOperator = (DbOperator) params;
			dbOperator.prepareStatement(this.sql);

			ResultSet rs = dbOperator.executeQuery();

			while (rs.next())
			{
				int id = rs.getInt("id");
				idList.add(id);
			}

			ret = true;
		}
		catch (Exception ex)
		{
			ret = false;
		}

		return ret;
	}
}
